<template>
  <div class="trapezoids">
    <!-- 第一个梯形 -->
    <div class="trapezoid trapezoid1">
      <div class="price">
        <div style="color: #fff; display: flex; align-items: center; ">￥
          <span style=" font-size: 1.7006rem;">{{ props.item.price }}</span>
          <span class="xg">限购5份</span>
        </div>
        <div style="font-size: .7936rem; color: #d1d1d1;">￥{{ props.item.original }} <span
            style="margin: .2834rem;">已卖300份 </span></div>
      </div>
    </div>
    <!-- 第二个梯形 -->
    <div class="trapezoid trapezoid2">
      <button style="border:none;background-color: rgb(170, 170, 170);">
        <span style="padding-left: 10px;">距秒杀结束秒杀</span>
        <van-count-down :time="time" format=" HH : mm : ss"
          />
      </button>
    </div>
  </div>
  <div class="info">
    <div class="info-top">{{ props.item.name }}</div>
    <div class="info-bottom">
      <div class="wy">
        <div>
          无忧保障
        </div>
        <div style="color: #b97c1f;">平台保价 7天物流有退货 闪电退款</div>
        <div>
          <van-icon name="arrow" />
        </div>
      </div>
      <div class="countdown">
        <div>
          提货信息
        </div>
        <div>
          现在下单 明日16:00可提货
        </div>
        <div>
          <van-icon name="arrow" />
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';

const time = ref(30 * 60 * 60 * 1000);
const props = defineProps({
  item: Object
})
// const price = ref('17.9');
// const originalPrice = '￥28.90';
// const soldQuantity = 300;

// 倒计时时钟
const hours = ref('');
const minutes = ref('');
const seconds = ref('');

function startTimer() {
  let countDownDate = new Date().getTime() + 10 * 60 * 1000; // 设置为10分钟后

  var x = setInterval(function () {

    // 获取当前日期和时间
    var now = new Date().getTime();

    // 计算剩余时间
    var distance = countDownDate - now;

    // 计算小时、分钟和秒数
    var tHours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
    var tMinutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
    var tSeconds = Math.floor((distance % (1000 * 60)) / 1000);

    // 显示结果
    hours.value = tHours < 10 ? `0${tHours}` : tHours;
    minutes.value = tMinutes < 10 ? `0${tMinutes}` : tMinutes;
    seconds.value = tSeconds < 10 ? `0${tSeconds}` : tSeconds;

    // 如果倒计时结束，则清除定时器并显示“结束了”
    if (distance < 0) {
      clearInterval(x);
      hours.value = "00";
      minutes.value = "00";
      seconds.value = "00";
    }
  }, 1000);
}




// 开始倒计时
startTimer();
</script>

<style scoped lang="less">
.trapezoids {
  // display: flex;
  // justify-content: center;
  // align-items: center;
  // height: 100vh;
  gap: 0;
  /* 确保没有间距 */
}

.trapezoid {
  /* 梯形的底部宽度 */
  height: 3.968rem;
  /* 梯形的高度 */
}


.trapezoid1 {
  background-color: #666666;
  display: flex;
  flex-direction: column;
  justify-content: center;
  width: 70%;
  // float: left;
  z-index: 10;
  clip-path: polygon(0 0, 100% 0, 90% 100%, 0 100%);
}

.trapezoid2 {
  background-color: #aaaaaa;
  width: 40%;
  position: relative;
  transform: translateY(-100%);
  float: right;
  clip-path: polygon(10% 0, 100% 0, 100% 100%, 0 100%);
}

.xg {
  color: #ff4848;
  font-size: 0.8rem;
  display: inline-block;
  background-color: #fff;
  padding: .2834rem;
  text-align: center;
  border-top-left-radius: .8503rem;
  border-bottom-right-radius: .8503rem;
  border-top-right-radius: .8503rem;
  margin-left: .2834rem;
}

.price {
  display: flex;
  // justify-content: space-between;
  flex-direction: column;
  // align-items: center;
  padding: 0 1rem;
  color: #fff;
  font-size: 1.2rem;
}

.info {
  .info-top {
    padding: 1rem 1rem;
    font-size: 1rem;
    background-color: #fff;
  }

  .info-bottom {
    .wy {
      padding: .8rem 1rem;
      font-size: 1rem;
      display: flex;
      justify-content: space-between;
      width: 100%;
      background-color: #fff;
    }

    .countdown {
      padding: .8rem 1rem;
      font-size: 1rem;
      display: flex;
      justify-content: space-between;
      width: 100%;
      background-color: #fff;
    }
  }
}
</style>